import { createSlice } from "@reduxjs/toolkit";

const countSlice=createSlice({
    name:"count",
    initialState:{
        count:localStorage.getItem("count")?Number(localStorage.getItem("count")):0,
    },
    reducers:{
        changeCount(state,actions){
            state.count+=actions.payload
            localStorage.setItem("count",state.count)
        },
        resetCount(state){
            state.count=0
            localStorage.removeItem("count")
        }
        // localStorage.clear()是删除所有缓存数据
    }

})

export const {changeCount,resetCount}=countSlice.actions
export default countSlice.reducer